package Test6;

public class GirlFriendTest {
    public static void main(String[] args) {
        //需求：
        //定义数组存储4个女朋友的对象
        //女朋友的属性：姓名，年龄，性别，爱好
        //要求1：计算出四个女朋友的平均年龄
        //要求2：统计年龄比平均值低的女朋友有几个，并把她们的所有信息打印出来

        //1.定义数组
        GirlFriend[] arr = new GirlFriend[4];

        //2.创建女朋友对象
        GirlFriend gf1 = new GirlFriend("小诗诗", 18, "萌妹子", "吃零食");
        GirlFriend gf2 = new GirlFriend("小丹丹", 19, "萌妹子", "玩游戏");
        GirlFriend gf3 = new GirlFriend("小惠惠", 20, "萌妹子", "看书，学习");
        GirlFriend gf4 = new GirlFriend("小莉莉", 21, "憨妹子", "睡觉");

        //3.把对象添加到数组当中
        arr[0] = gf1;
        arr[1] = gf2;
        arr[2] = gf3;
        arr[3] = gf4;

        //4.计算出四个女朋友的平均年龄
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum += arr[i].getAge();
        }
        int avg = sum / arr.length;
        System.out.println("四个女朋友的平均年龄是：" + avg);

        //5.统计年龄比平均值低的女朋友有几个，并把她们的所有信息打印出来
        System.out.println("年龄比平均值低的女朋友的所有信息如下：");
        int count = 0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i].getAge() < avg) {
                count++;
                System.out.println(arr[i].getName() + "," + arr[i].getAge() + "," + arr[i].getGender() + "," + arr[i].getHobby());
            }
        }
        System.out.println("年龄比平均值低的女朋友有" + count + "个");
    }
}
